package weather;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Random;
import javax.swing.Timer;

/**
 *
 * @author Sebas
 */
public class WindData extends Observable {

    private float speed;
    private float visibility;
    private char direction;
    private int i;

   public WindData() {
            i=0;
                Timer timer = new Timer (1000, new ActionListener ()
         {
             public void actionPerformed(ActionEvent e)
             {
                 Random rdn = new Random();
                 int x = (int)(rdn.nextDouble()*10);
                 if(x==5||i==60){
                 float speed = (rdn.nextFloat()*50)-10;
                 float visib = (rdn.nextFloat()*30)+40;
                 int flag = (int)rdn.nextDouble()*3;
                 char dir = 0;
                 if(flag==0)
                     dir='N';
                 if(flag==1)
                     dir='S';
                 if(flag==2)
                     dir='E';
                 if(flag==3)
                     dir='W';
                 setMeasurements(speed,visib,dir);
                 i=0;
                 }
                 i=i+1;
             }
         });
         timer.start();
   }

    public void measurementsChanged() {
        setChanged();
        notifyObservers();
    }

    public void setMeasurements(float spd, float vsblt, char drctn) {
        this.setSpeed(spd);
        this.setVisibility(vsblt);
        this.setDirection(drctn);
        measurementsChanged();
    }

    public float getSpeed() {
        return speed;
    }

    public void setSpeed(float speed) {
        this.speed = speed;
    }

    public float getVisibility() {
        return visibility;
    }

    public void setVisibility(float visibility) {
        this.visibility = visibility;
    }

    public char getDirection() {
        return direction;
    }

    public void setDirection(char direction) {
        this.direction = direction;
    }
}